import React, { Component } from 'react';
import { BrowserRouter } from 'react-router-dom';
import RouteMap from './route/index';
// import Utils from './utils/utils'
// import { Toast } from 'antd-mobile'
// import { qeuryUserInfoByCode } from './api/api'
// import cookie from 'react-cookies'
// import IP from './config/config'
import 'antd/dist/antd.css';

class App extends Component {

  state = {
    isShow: true
  }

  // componentDidMount = () => {
  //   this.handleLogin()
  // }

  // handleLogin = async () => {
  //   const code = Utils.GetQueryString('code');
  //   const url = Utils.GetQueryString('state');
  //   // if (!code) return window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${IP.appId}&redirect_uri=${IP.wxredirect}&response_type=code&scope=snsapi_base&state=STATE&connect_redirect=1#wechat_redirect`;
  //   if (code) {
  //     const result = await qeuryUserInfoByCode({ code })
  //     if (result.code !== 20000) {
  //       if (result.code === 40029) {
  //         return window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${IP.appId}&redirect_uri=${IP.wxredirect}&response_type=code&scope=snsapi_base&state=&connect_redirect=1#wechat_redirect`
  //       }
  //       return Toast.fail(result.message)
  //     }
  //     cookie.save('token', result.data)
  //     if (!url) {
  //       this.setState({
  //         isShow: true
  //       })
  //     } else {
  //       const redirectPath = url.includes('?') ? `${url}&token=${cookie.load('token')}` : `${url}?token=${cookie.load('token')}`;
  //       return window.location.href = redirectPath;
  //     }
  //   } else {
  //     const path = Utils.GetQueryString('path');
  //     if (path) {
  //       window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${IP.appId}&redirect_uri=${IP.wxredirect}&response_type=code&scope=snsapi_base&state=${path || ''}&connect_redirect=1#wechat_redirect`;
  //     } else {
  //       window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${IP.appId}&redirect_uri=${IP.wxredirect}&response_type=code&scope=snsapi_base&state=&connect_redirect=1#wechat_redirect`;
  //     }
  //   }
  // }

  render() {
    const { isShow } = this.state
    return (
      <div>
        {isShow && <BrowserRouter>
          <RouteMap />
        </BrowserRouter>}
      </div>
    )
  }
}

export default App;